package com.mz.ozy.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.mz.ozy.R;
import com.mz.ozy.bean.GoodsCategoryBean;

import java.util.List;

public class SortPopAdapter extends BaseQuickAdapter<GoodsCategoryBean.CateListBean, BaseViewHolder> {

    private int selectPosition = -1;
    private String id;

    public SortPopAdapter(@Nullable List<GoodsCategoryBean.CateListBean> data, String id) {
        super(R.layout.item_brand_pop_grid, data);
        this.id = id;
        if (data != null && data.size() > 0) {
            for (int i = 0; i < data.size(); i++) {
                GoodsCategoryBean.CateListBean cateListBean = data.get(i);

                this.id = (this.id).replace(",", "");
                if (!TextUtils.isEmpty(this.id) && Integer.parseInt(this.id) == cateListBean.getId()) {
                    selectPosition = i;
                }
            }
        }
    }

    public void setSelectPosition(int selectPosition) {
        this.selectPosition = selectPosition;
    }

    @Override
    protected void convert(BaseViewHolder helper, GoodsCategoryBean.CateListBean item) {
        helper.setText(R.id.brandNameTv, item.getName());
        if (selectPosition == helper.getAdapterPosition()) {
            helper.setVisible(R.id.iv_sort_select, true);
            helper.setTextColor(R.id.brandNameTv, mContext.getResources().getColor(R.color.c_fbcc14));
        } else {
            helper.setVisible(R.id.iv_sort_select, false);
            helper.setTextColor(R.id.brandNameTv, mContext.getResources().getColor(R.color.c_363636));
        }
    }

}
